package com.readfeed.app.data;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ChannelsTable {
	public static final String TABLE_CHANNELS_NAME = "channels";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_TITLE = "title";
	public static final String COLUMN_URI = "link";
	public static final String COLUMN_DESCRIPTION = "description";
	public static final String COLUMN_CATEGORY_ID = "category_id";
	public static final String COLUMN_UPDATE = "last_update";
	
	private static final String DATABASE_CREATE = "create table " 
		      + TABLE_CHANNELS_NAME
		      + "(" 
		      + COLUMN_ID + " integer primary key autoincrement, " 
		      + COLUMN_TITLE + " nvarchar(30) not null," 
		      + COLUMN_DESCRIPTION + " text,"
		      + COLUMN_URI + " text not null,"
		      + COLUMN_UPDATE + " integet not null, "
		      + COLUMN_CATEGORY_ID + " integer references " 
		      + CategoriesTable.TABLE_CATEGORIES_NAME
		      + "(" + CategoriesTable.COLUMN_ID + ") not null"
		      + ");";
	
	public static void onCreate(SQLiteDatabase database){
		database.execSQL(DATABASE_CREATE);		
	}

	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion){
		Log.w(ChannelsTable.class.getName(), "Upgrading database from version "
		        + oldVersion + " to " + newVersion);
		    database.execSQL("DROP TABLE IF EXISTS " + TABLE_CHANNELS_NAME);
		    onCreate(database);
	}
}
